var app = getApp() // 获取入口文件app的应用实例
Page({
  data: {
    items: ,
    hidden: false,
    loading: false,
    // loadmorehidden:true,
    plain: false
  },
  Tianapi: function () {
    //打开天行数据
  },
  onItemClick: function (event) {
      wx.previewImage({
        current: event.currentTarget.dataset.url, // 当前显示图片的http链接
        urls: [event.currentTarget.dataset.url] // 需要预览的图片http链接列表
      })
  },

  onReachBottom: function () {
    console.log('onLoad')
    var that = this
    that.setData({
      hidden: false,
    });
    requestData(that, mCurrentPage + 1);
  },

  onLoad: function () {
    //转发
    wx.showShareMenu({
      withShareTicket: true
    })
    console.log('onLoad')
    var that = this
    requestData(that, mCurrentPage + 1);
  }

})

/**
 * 定义几个数组用来存取item中的数据
 */

var mUrl = ;
var mDesc = ;
var mAuthor = ;
var mTimes = ;
var mTitles = ;
var mCurrentPage = 0;

/**
 * 定义天行数据APIKEY
 * *apikey请在https://www.tianapi.com中获得
 */

var apikey = '把你在天行数据获得的APIKEY替换到这里' 

/**
 * 请求数据
 */

function requestData(that, targetPage) {
  wx.showToast({
    title: '图片加载中',
    icon: 'loading'
  });
  wx.request({
    url: 'https://api.tianapi.com/meinv/',
    data: {
      key: apikey,        //天行数据的APIKEY
      num:10,             //每次请求返回的数量
      page: targetPage    //翻页
    },
    header: {
      "Content-Type": "application/json"
    },
    success: function (res) {
      if (res == null ||
        res.data == null ||
        res.data.newslist == null ||
        res.data.newslist.length <= 0) {

        console.error(res.data.msg);
        return;
      }


      for (var i = 0; i < res.data.newslist.length; i++)
        bindData(res.data.newslist[i]);

[/i]      var itemList = ;
      for (var i = 0; i < mUrl.length; i++)
        itemList.push({ url: mUrl, desc: mDesc, author: mAuthor, time: mTimes, title: mTitles });

      that.setData({
        items: itemList,
        hidden: true,
      });

      mCurrentPage = targetPage;

      wx.hideToast();
    }
  });
}

/**
 * 绑定接口中返回的数据
 */

function bindData(itemData) {

  var url = itemData.picUrl;
  var desc = itemData.description;
  var author = itemData.description;
  var times = itemData.ctime;
  var title = itemData.title;

  mUrl.push(url);
  mDesc.push(desc);
  mAuthor.push(author);
  mTimes.push(times);
  mTitles.push("作者：" + author + " — " + title + " — " + times);
}